<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<table id="task_table">
    <thead>
    <th data-options="field:'id'">ID</th>
    <th data-options="field:'user',formatter:userFormatter">请假人</th>
    <th data-options="field:'date',formatter:dateFormater">请假时间</th>
    </thead>
</table>
<div id="task_tool">
    <a href="#" class="easy-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="doTaskAdd()">审批</a>
</div>
<div id="task_dialog" class="easyui-dialog" title="编辑请假条"
     data-options="modal:true,closed:true,href:'<%=request.getContextPath()%>/system/task.html?act=go_edit',footer:'#task_buttons'"
     style="width: 480px;height: 300px">
    s
</div>
<div id="task_buttons" style="padding: 5px 15px 5px 0px;text-align: right">
    <a href="#" class="easy-linkbutton" data-options="iconCls:'icon-ok'" onclick="submitTaskForm()">提交</a>
    <a href="#" class="easy-linkbutton" onclick="doCancel('task_dialog')">取消</a>
</div>

<script type="text/javascript">
    function dateFormater(value,row,index) {
        return row.startDate+"-"+row.endDate;
    }
    function userFormatter(value,row,index) {
        debugger
        return row.user.realName;
    }
    $(function () {
        $("#task_table").datagrid({
            url:"/system/task.html?act=list",
            singleSelect:true,
            toolbar:"#task_tool"
        })
    })

    function doTaskAdd() {
        var row = $("#task_table").datagrid("getSelected");
        if (row == null || row.length == 0){
            return;
        }
        $("#task_dialog").dialog({
            onLoad:function () {
                $("#task_form").form("load",{
                    id:row.id,
                })
            }
        }).dialog("open");
    }

    function doCancel(domId) {
        $("#"+domId).dialog("close")
    }

    function submitTaskForm() {
        $.ajax({
            url:"<%=request.getContextPath()%>/system/task.html?act=advise",
            data:$("#task_form").serialize(),
            mothod:"post",
            success:function (result) {
                if (result.status){
                    $("#task_dialog").dialog("close");
                    $("#task_table").datagrid("load");
                }else {
                    alert(result.message);
                }
            }
        })
    }
</script>

